package initialize

import (
	middlewares "go_final/mxshop_api/order_web/middleware"
	router2 "go_final/mxshop_api/order_web/router"
	"net/http"

	"github.com/gin-gonic/gin"
)

func Routers() *gin.Engine {
	router := gin.Default()

	// 用于健康检查
	router.GET("/health", func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{
			"code":    http.StatusOK,
			"success": true,
		})
	})

	// 解决跨域问题
	router.Use(middlewares.Cors())

	ApiGroup := router.Group("/v1")
	ApiGroup.Use(middlewares.Trace())
	router2.InitOrderRouter(ApiGroup)
	router2.InitShopCartRouter(ApiGroup)

	return router
}
